package com.example.myblog.common;

import com.example.myblog.entity.UserInfo;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

/*
    用户session相关操作
 */
public class UserSessionUtils {
    public static UserInfo getUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);//默认不创建
        if (session != null && session.getAttribute(GloableVariable.USER_SESSION_KEY) != null) {
            return (UserInfo) session.getAttribute(GloableVariable.USER_SESSION_KEY);
        }
        return null;
    }
}
